package cn.edu.scau.cmi.wujiaxian.exercise11;

import java.util.Arrays;

import javax.swing.JTextArea;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class PoliceListen3 implements DocumentListener{

	JTextArea inputArea;
	JTextArea outputArea;
	
	public void setInputArea(JTextArea inputArea) {
		this.inputArea = inputArea;
	}

	public void setOutputArea(JTextArea outputArea) {
		this.outputArea = outputArea;
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		changedUpdate(e);
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		changedUpdate(e);
	}

	@Override
	public void changedUpdate(DocumentEvent e) {
		String string = inputArea.getText();
		String regex = "[\\s\\d\\p{Punct}]+";
		String[] words = string.split(regex);
		Arrays.sort(words);
		outputArea.setText(null);
		for (String s : words) {
			outputArea.append(s + ",");
		}
	}


	
}
